<template>
  <div class="app-container">
    <el-card class="filter-container" shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
        <el-button
            style="float:right"
            type="primary"
            @click="handleSearchList()"
            size="small">
          查询搜索
        </el-button>
        <el-button
            style="float:right;margin-right: 15px"
            @click="handleResetSearch()"
            size="small">
          重置
        </el-button>
      </div>
      <div style="margin-top: 15px">
        <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
          <el-form-item label="接口名称：">
            <el-input v-model="listQuery.name" class="input-width" placeholder="" clearable></el-input>
          </el-form-item>
          <el-form-item label="访问人：">
            <el-input v-model="listQuery.username" class="input-width" placeholder="" clearable></el-input>
          </el-form-item>
          <el-form-item label="访问状态：">
            <el-input v-model="listQuery.status" class="input-width" placeholder="" clearable></el-input>
          </el-form-item>

        </el-form>
      </div>
    </el-card>

    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
      <el-button type="warning" v-if="false" size="mini" class="btn-add" @click="handleAdd()" style="margin-left: 20px">
        添加
      </el-button>
      <el-button type="primary" v-if="false" size="mini" class="btn-add" @click="handleBatchAdd()"
                 style="margin-left: 20px">批量导入
      </el-button>
    </el-card>

    <div class="table-container">
      <el-table ref="roleTable"
                :data="list"
                style="width: 100%;"
                v-loading="listLoading" border>
        <el-table-column label="接口名称" align="center" prop="name" show-overflow-tooltip/>
        <el-table-column label="接口地址" align="center" prop="url" show-overflow-tooltip/>
        <el-table-column label="访问人IP" align="center" prop="ip" show-overflow-tooltip/>
        <el-table-column label="访问人" align="center" prop="username" show-overflow-tooltip/>
        <el-table-column label="访问状态" align="center" prop="status" show-overflow-tooltip/>
        <el-table-column label="接口执行时间" align="center" prop="executeTime" show-overflow-tooltip/>
        <el-table-column label="开始时间" align="center" prop="createTime" show-overflow-tooltip/>

      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          layout="total, sizes,prev, pager, next,jumper"
          :current-page.sync="listQuery.current"
          :page-size="listQuery.pageSize"
          :page-sizes="[5,10,15]"
          :total="total">
      </el-pagination>
    </div>
    <el-dialog title="编辑系统管理 - 日志表"
               :visible.sync="editDialogVisible"
               width="80%">
      <el-form :model="sysLog"
               ref="roleForm"
               label-width="150px" size="small">

      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="handleEditDialogConfirm()" size="small">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog title="新增系统管理 - 日志表"
               :visible.sync="addDialogVisible"
               width="80%">
      <el-form :model="sysLog"
               ref="roleForm"
               label-width="150px" size="small">

      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="handleAddDialogConfirm()" size="small">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>
<script>
import {sysLogPostRequire} from '@/api/sysLog'

const defaultListQuery = {
  current: 1,
  pageSize: 10,
  name: undefined,
  username: undefined,
  status: undefined,

}
const defaultSysLog = {
  id: undefined,
  name: undefined,
  url: undefined,
  ip: undefined,
  username: undefined,
  userId: undefined,
  status: undefined,
  executeTime: undefined,
  createTime: undefined,
  endTime: undefined,

}
export default {
  name: 'sysLogList',
  data() {
    return {
      listQuery: this.$deepClone( defaultListQuery),
      list: null,
      total: null,
      listLoading: false,
      addDialogVisible: false,
      editDialogVisible: false,
      sysLog: this.$deepClone( defaultSysLog)
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleResetSearch() {
      this.listQuery = this.$deepClone( defaultListQuery)
    },
    handleSearchList() {
      this.listQuery.current = 1
      this.getList()
    },
    handleSizeChange(val) {
      this.listQuery.current = 1
      this.listQuery.pageSize = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listQuery.current = val
      this.getList()
    },
    handleAdd() {
      this.addDialogVisible = true
      this.sysLog = this.$deepClone( defaultSysLog)
    },
    handleBatchAdd() {

    },
    handleUpdate(index, row) {
      this.editDialogVisible = true
      this.sysLog = this.$deepClone( row)
    },
    handleEditDialogConfirm() {
      sysLogPostRequire('update', this.sysLog).then(response => {
        if (response) {
          this.$message({
            message: response.message,
            type: response.status ? 'success' : 'error'
          })
        }
        this.editDialogVisible = false
      }).finally(() => {
        this.getList()
      })
    },
    handleAddDialogConfirm() {
      sysLogPostRequire('add', this.sysLog).then(response => {
        if (response) {
          this.$message({
            message: response.message,
            type: response.status ? 'success' : 'error'
          })
        }
        this.addDialogVisible = false
      }).finally(() => {
        this.getList()
      })
    },
    getList() {
      this.listLoading = true
      sysLogPostRequire('listPage', this.listQuery).then(response => {
        this.listLoading = false
        this.list = response.data.records
        this.total = response.data.total
      })
    }
  }
}
</script>
<style></style>
